use std::cmp::PartialEq;
use chrono::{DateTime, Local};

pub struct Counter {
    fail: u16,
    success: u16,
    skipped: u16,
    start_time: Option<DateTime<Local>>,
    end_time: Option<DateTime<Local>>,
}

impl Counter {
    pub fn default() -> Counter {
        Counter{
            fail:0,
            success:0,
            skipped:0,
            start_time: Some(Local::now()),
            end_time: None
        }
    }

    pub fn increase_fail(&mut self) {
        self.fail += 1;
    }

    pub fn increase_success(&mut self) {
        self.success += 1;
    }

    pub fn increase_skipped(&mut self) {
        self.skipped += 1;
    }

    pub fn get_fail(&self) -> u16 {
        self.fail
    }

    pub fn get_success(&self) -> u16 {
        self.success
    }

    pub fn get_skipped(&self) -> u16 {
        self.skipped
    }

    pub fn init_end_time(&mut self) {
        self.end_time = Some(Local::now());
    }

    pub fn time_diff_seconds(&self) -> i64{
        match (self.start_time, self.end_time) {
            (Some(start), Some(end)) => (end - start).num_seconds(),
            _ => 0i64,
        }
    }

    pub fn get_start_time_str(&self) -> String {
        if let Some(start_time) = self.start_time {
            return start_time.format("%F %T").to_string();
        }
        Local::now().format("%F %T").to_string()
    }

    pub fn get_end_time_str(&self) -> String {
        if let Some(end_time) = self.end_time {
            return end_time.format("%F %T").to_string();
        }
        Local::now().format("%F %T").to_string()
    }
}

#[derive(Clone, Copy, PartialEq, Debug)]
pub enum Cate{
    APPID,
    SUBID,
}


impl Cate {
    pub fn to_string(&self) -> String {
        match self {
            Cate::APPID => "appid".to_string(),
            Cate::SUBID => "subid".to_string(),
        }
    }
}